package com.lc.admin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lc.admin.base.PageResponse;
import com.lc.admin.bean.NursingProject;
import com.lc.admin.mapper.NursingProjectMapper;
import com.lc.admin.service.NursingProjectService;
import com.lc.admin.utils.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProject> list(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);

        List<NursingProject> nursingProjectList = nursingProjectMapper.list(name,status);
        Page page = (Page)nursingProjectList;


        PageResponse pageResponse = new PageResponse<NursingProject>(page);
        pageResponse.setRecords(page.getResult());


        return pageResponse;
    }

    @Override
    public void save(NursingProject nursingProject) {
        Long uid = UserThreadLocal.getUserId();
        nursingProject.setCreateBy(uid);
        nursingProjectMapper.save(nursingProject);
    }

    @Override
    public NursingProject findById(Long id) {
        return nursingProjectMapper.findById(id);
    }

    @Override
    public void edit(NursingProject nursingProject) {
        nursingProjectMapper.edit(nursingProject);
    }

    @Override
    public void enable(Long id, Integer status) {
        nursingProjectMapper.enable(id,status);
    }

    @Override
    public void del(Integer id) {
        nursingProjectMapper.del(id);
    }
}
